//package com.ruoyi.auth.config;
//
//import com.google.common.collect.Lists;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.OAuthBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.contexts.SecurityContext;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @Author haoxr
// * @Date 2021-02-25 15:36
// * @Version 1.0.0
// */
//@Configuration
//@EnableSwagger2WebMvc
//public class SwaggerConfiguration {
//
//    @Value("${knife4j.password_token_url}")
//    private String passwordTokenUrl;
//
//    @Bean
//    public Docket restApi() {
//        //schema
//        List<GrantType> grantTypes=new ArrayList<>();
//        //密码模式
//        ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant=new ResourceOwnerPasswordCredentialsGrant(passwordTokenUrl);
//        grantTypes.add(resourceOwnerPasswordCredentialsGrant);
//        OAuth oAuth=new OAuthBuilder().name("oauth2")
//                .grantTypes(grantTypes).build();
//        //context
//        //scope方位
//        List<AuthorizationScope> scopes=new ArrayList<>();
//        scopes.add(new AuthorizationScope("read","read  resources"));
//        scopes.add(new AuthorizationScope("write","write resources"));
//        scopes.add(new AuthorizationScope("reads","read all resources"));
//        scopes.add(new AuthorizationScope("writes","write all resources"));
//
//        SecurityReference securityReference=new SecurityReference("oauth2",scopes.toArray(new AuthorizationScope[]{}));
//        SecurityContext securityContext=new SecurityContext(Lists.newArrayList(securityReference),PathSelectors.ant("/**"));
//        //schemas
//        List<SecurityScheme> securitySchemes= Lists.newArrayList(oAuth);
//        //securyContext
//        List<SecurityContext> securityContexts= Lists.newArrayList(securityContext);
//        return new Docket(DocumentationType.SWAGGER_2)
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.youlai.auth.controller"))
//                .paths(PathSelectors.any())
//                .build()
//                .securityContexts(securityContexts)
//                .securitySchemes(securitySchemes)
//                .apiInfo(apiInfo());
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder().title("OAuth2认证中心")
//                .description("<div style='font-size:14px;color:red;'>OAuth2认证、注销、获取验签公钥接口</div>")
//                .termsOfServiceUrl("https://www.youlai.tech")
//                .contact(new Contact("有来技术团队", "https://gitee.com/youlaiorg", "youlaitech@163.com"))
//                .license("Open Source")
//                .licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
//                .version("1.0.0")
//                .build();
//    }
//
//}
